fix: sbom Search by name instead of full search#1134
Conversation
Signed-off-by: Carlos Feria <2582866+carlosthe19916@users.noreply.github.com>
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts SBOM search behavior so that both the main search and autocomplete query the SBOM API by name only, and aligns SBOM filter configuration/types so that the name filter is driven from the top search bar while the sidebar text filter is hidden for SBOMs but other entity searches remain unchanged. Sequence diagram for updated SBOM search by namesequenceDiagram
actor User
participant Search as SearchPage
participant SearchMenu
participant useAllEntities
participant useFetchSBOMs
participant SBOM_API
User->>Search: type searchValue
User->>Search: press Enter
Search->>SearchMenu: set searchValue
SearchMenu->>useAllEntities: useAllEntities(filterText, disableSearch)
useAllEntities->>useFetchSBOMs: useFetchSBOMs(null, sbomParams, [], disableSearch)
note over useAllEntities,useFetchSBOMs: sbomParams.filters = [ { field: name, operator: ~, value: filterText } ]
useFetchSBOMs->>SBOM_API: GET /api/v3/sbom?q=name~filterText
SBOM_API-->>useFetchSBOMs: sbom results
useFetchSBOMs-->>useAllEntities: sboms
useAllEntities-->>SearchMenu: suggestions and results
SearchMenu-->>User: updated SBOM search and autocomplete
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The string literal "name" is now duplicated in several places (filter categories, omitFilterCategoryKeys, filterState usage); consider centralizing it in a shared constant or type-safe enum to avoid drift and typos.
- Since the SBOM filter panel now hides the name filter while still configuring it in the provider, it may be worth clarifying whether the label/placeholder (currently "Filter text") and behavior are still appropriate given it only targets the name field.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The string literal "name" is now duplicated in several places (filter categories, omitFilterCategoryKeys, filterState usage); consider centralizing it in a shared constant or type-safe enum to avoid drift and typos.
- Since the SBOM filter panel now hides the name filter while still configuring it in the provider, it may be worth clarifying whether the label/placeholder (currently "Filter text") and behavior are still appropriate given it only targets the name field.
## Individual Comments
### Comment 1
<location path="client/src/app/pages/sbom-list/sbom-provider.tsx" line_range="75" />
<code_context>
filterCategories: [
{
- categoryKey: FILTER_TEXT_CATEGORY_KEY,
+ categoryKey: "name",
title: "Filter text",
placeholderText: "Search",
</code_context>
<issue_to_address>
**suggestion:** Consider centralizing the `"name"` filter key instead of hardcoding it.
This key is now referenced in multiple places (provider, search menu, search tabs, `setFilterValues`, etc.), so hardcoding it in each file increases the risk of inconsistencies if it ever changes. Exposing a shared constant (like the previous `FILTER_TEXT_CATEGORY_KEY`) and reusing it would keep the key definition in one place and make future changes safer.
Suggested implementation:
```typescript
isFilterEnabled: true,
filterCategories: [
{
categoryKey: FILTER_TEXT_CATEGORY_KEY,
title: "Filter text",
placeholderText: "Search",
type: FilterType.search,
```
1. Ensure `FILTER_TEXT_CATEGORY_KEY` is defined in a shared constants module (e.g. `client/src/app/pages/sbom-list/constants.ts` or an existing filters-constants file), with a value of `"name"`, and exported:
- `export const FILTER_TEXT_CATEGORY_KEY = "name";`
2. Import `FILTER_TEXT_CATEGORY_KEY` at the top of `sbom-provider.tsx` from that shared constants module:
- `import { FILTER_TEXT_CATEGORY_KEY } from "./constants";` (or the correct relative path for your project).
3. In all other places that currently hardcode `"name"` for this same filter (provider, search menu, search tabs, `setFilterValues`, etc.), replace the string literal with `FILTER_TEXT_CATEGORY_KEY` and add the same import there. This keeps the filter key centralized and consistent.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| filterCategories: [ | ||
| { | ||
| categoryKey: FILTER_TEXT_CATEGORY_KEY, | ||
| categoryKey: "name", |
There was a problem hiding this comment.
suggestion: Consider centralizing the "name" filter key instead of hardcoding it.
This key is now referenced in multiple places (provider, search menu, search tabs, setFilterValues, etc.), so hardcoding it in each file increases the risk of inconsistencies if it ever changes. Exposing a shared constant (like the previous FILTER_TEXT_CATEGORY_KEY) and reusing it would keep the key definition in one place and make future changes safer.
Suggested implementation:
isFilterEnabled: true,
filterCategories: [
{
categoryKey: FILTER_TEXT_CATEGORY_KEY,
title: "Filter text",
placeholderText: "Search",
type: FilterType.search,- Ensure
FILTER_TEXT_CATEGORY_KEYis defined in a shared constants module (e.g.client/src/app/pages/sbom-list/constants.tsor an existing filters-constants file), with a value of"name", and exported:export const FILTER_TEXT_CATEGORY_KEY = "name";
- Import
FILTER_TEXT_CATEGORY_KEYat the top ofsbom-provider.tsxfrom that shared constants module:import { FILTER_TEXT_CATEGORY_KEY } from "./constants";(or the correct relative path for your project).
- In all other places that currently hardcode
"name"for this same filter (provider, search menu, search tabs,setFilterValues, etc.), replace the string literal withFILTER_TEXT_CATEGORY_KEYand add the same import there. This keeps the filter key centralized and consistent.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1134 +/- ##
==========================================
- Coverage 53.08% 53.07% -0.02%
==========================================
Files 270 270
Lines 5879 5879
Branches 1843 1842 -1
==========================================
- Hits 3121 3120 -1
Misses 2455 2455
- Partials 303 304 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Backport failed for Please cherry-pick the changes locally and resolve any conflicts. git fetch origin release/0.5.z
git worktree add -d .worktree/backport-1134-to-release/0.5.z origin/release/0.5.z
cd .worktree/backport-1134-to-release/0.5.z
git switch --create backport-1134-to-release/0.5.z
git cherry-pick -x 2e45be37c561d10f0506935e82f48654f8fff974 |
|
/backport |
|
Successfully created backport PR for |
Summary
Fixes https://redhat.atlassian.net/browse/TC-5046
The Search page (/search) was sending SBOM API requests as:
This performs a full-text search across all fields. As Requested in the jira linked above, for performance reasons we should change it to:
What changed
Related Issues
guacsec/trustify#2440
Summary by Sourcery
Update SBOM search to query by name instead of full-text and align UI filters with the new search behavior.
Bug Fixes:
Enhancements: